package api

import (
	"gitee.com/DengAnbang/Wefore/src/bean"
	"gitee.com/DengAnbang/Wefore/src/dbops"
	"gitee.com/DengAnbang/Wefore/src/fun"
	"gitee.com/DengAnbang/goutils/httpUtils"
	"net/http"
)

/**
* showdoc
* @catalog 接口文档/考勤
* @title 上班签到
* @description 上班签到,多次调用会返回今天已经打过卡的错误
* @method socket type=601
* @url /pc/attendance/punch/in
* @param userId 必填 string 用户的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"打卡成功!"}
* @remark 最后修改时间:2018.12.07 10.30
* @number 1
 */
func AttendancePunchInHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	err := dbops.AttendancePunchIn(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("打卡成功!")

}
func AttendancePunchInSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	err := dbops.AttendancePunchIn(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("打卡成功!")
}

/**
* showdoc
* @catalog 接口文档/考勤
* @title 下班签到
* @description 下班签到,多次调用会覆盖之前的下班签到,即以最后一次签到为准
* @method socket type=602
* @url /pc/attendance/punch/out
* @param userId 必填 string 用户的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"打卡成功!"}
* @remark 最后修改时间:2018.12.07 10.30
* @number 1
 */
func AttendancePunchOutHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	err := dbops.AttendancePunchOut(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("打卡成功!")

}
func AttendancePunchOutSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	err := dbops.AttendancePunchOut(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("打卡成功!")
}

/**
* showdoc
* @catalog 接口文档/考勤
* @title 打卡记录查询(某个人)
* @description 打卡记录查询
* @method socket type=603
* @url /pc/attendance/select
* @param userId 必填 string 用户的id
* @param startTime 必填 string 开始的时间,格式:2006-01-02
* @param endTime 必填 string 结束的时间,格式:2006-01-02
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]attendance}
* @remark 最后修改时间:2018.12.07 10.30
* @number 3
 */
func AttendanceSelectHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	startTime := httpUtils.GetValueFormRequest(r, "startTime")
	endTime := httpUtils.GetValueFormRequest(r, "endTime")
	attendances, err := dbops.AttendanceSelect(userId, startTime, endTime)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(attendances)

}
func AttendanceSelectSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	startTime := fun.GetString(parameters, "startTime")
	endTime := fun.GetString(parameters, "endTime")
	attendances, err := dbops.AttendanceSelect(userId, startTime, endTime)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(attendances)
}

/**
* showdoc
* @catalog 接口文档/考勤
* @title 创建请假条
* @description 创建请假条
* @method socket type=604
* @url /pc/attendance/askForLeave/create
* @param userId 必填 string 用户的id
* @param leaveType 必填 int 请假的类型
* @param leaveReason 必填 string 请假的原因
* @param startTime 必填 string 开始的时间,格式:2006-01-02
* @param endTime 必填 string 结束的时间,格式:2006-01-02
* @param askUserId 必填 string 审批人的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"提交成功!"}
* @remark 最后修改时间:2018.12.07 10.30
* @number 4
 */
func AttendanceAskForLeaveCreateHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	leaveType := httpUtils.GetValueFormRequest(r, "leaveType")
	leaveReason := httpUtils.GetValueFormRequest(r, "leaveReason")
	startTime := httpUtils.GetValueFormRequest(r, "startTime")
	endTime := httpUtils.GetValueFormRequest(r, "endTime")
	askUserId := httpUtils.GetValueFormRequest(r, "askUserId")
	err := dbops.AttendanceAskForLeaveCreate(userId, leaveType, leaveReason, startTime, endTime, askUserId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("提交成功!")

}
func AttendanceAskForLeaveCreateSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	leaveType := fun.GetString(parameters, "leaveType")
	leaveReason := fun.GetString(parameters, "leaveReason")
	startTime := fun.GetString(parameters, "startTime")
	endTime := fun.GetString(parameters, "endTime")
	askUserId := fun.GetString(parameters, "askUserId")
	err := dbops.AttendanceAskForLeaveCreate(userId, leaveType, leaveReason, startTime, endTime, askUserId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("提交成功!")
}

/**
* showdoc
* @catalog 接口文档/考勤
* @title 查询请假条
* @description 查询请假条
* @method socket type=605
* @url /pc/attendance/askForLeave/select/id
* @param askForLeaveId 必填 string 请假条的ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":AskForLeave}
* @remark 最后修改时间:2018.12.07 10.30
* @number 5
 */
func AttendanceAskForLeaveSelectByIdHttp(_ http.ResponseWriter, r *http.Request) error {
	askForLeaveId := httpUtils.GetValueFormRequest(r, "askForLeaveId")
	leave, err := dbops.AttendanceAskForLeaveSelectById(askForLeaveId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(leave)

}
func AttendanceAskForLeaveSelectByIdSocket(parameters map[string]interface{}) error {
	askForLeaveId := fun.GetString(parameters, "askForLeaveId")
	leave, err := dbops.AttendanceAskForLeaveSelectById(askForLeaveId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(leave)
}

/**
* showdoc
* @catalog 接口文档/考勤
* @title 查询某个人的请假条
* @description 查询某个人的所有请假条
* @method socket type=606
* @url /pc/attendance/askForLeave/select/userId
* @param userId 必填 string 用户的ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]AskForLeave}
* @remark 最后修改时间:2018.12.07 10.30
* @number 6
 */
func AttendanceAskForLeaveSelectByUserIdHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	leave, err := dbops.AttendanceAskForLeaveSelectByUserId(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(leave)

}
func AttendanceAskForLeaveSelectByUserIdSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	leave, err := dbops.AttendanceAskForLeaveSelectByUserId(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(leave)
}

/**
* showdoc
* @catalog 接口文档/考勤
* @title 审批请假条
* @description 审批请假条
* @method socket type=607
* @url /pc/attendance/askForLeave/approval
* @param userId 必填 string 请假人的id
* @param askForLeaveId 必填 string 请假条的ID
* @param askResult 必填 string 请假的回复-1拒绝,1同意
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"完成审批!"}
* @remark 最后修改时间:2018.12.07 10.30
* @number 7
 */
func AttendanceAskForLeaveApprovalHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	askForLeaveId := httpUtils.GetValueFormRequest(r, "askForLeaveId")
	askResult := httpUtils.GetValueFormRequest(r, "askResult")
	err := dbops.AttendanceAskForLeaveApproval(userId, askForLeaveId, askResult)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("完成审批!")

}
func AttendanceAskForLeaveApprovalSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	askForLeaveId := fun.GetString(parameters, "askForLeaveId")
	askResult := fun.GetString(parameters, "askResult")
	err := dbops.AttendanceAskForLeaveApproval(userId, askForLeaveId, askResult)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("完成审批!")
}

/**
* showdoc
* @catalog 接口文档/考勤
* @title 查询我的审批
* @description 查询我的审批
* @method socket type=608
* @url /pc/attendance/askForLeave/approval/select
* @param userId 必填 string 审批人的id
* @param isRead 必填 string 是否已经审批,0未审批,1以审批
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"完成审批!"}
* @remark 最后修改时间:2018.12.07 10.30
* @number 8
 */
func AttendanceAskForLeaveApprovalSelectHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	isRead := httpUtils.GetValueFormRequest(r, "isRead")
	leaves, err := dbops.AttendanceAskForLeaveApprovalSelect(userId, isRead)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(leaves)

}
func AttendanceAskForLeaveApprovalSelectSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	isRead := fun.GetString(parameters, "isRead")
	leaves, err := dbops.AttendanceAskForLeaveApprovalSelect(userId, isRead)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(leaves)
}
